<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="imlgw,半岛铁盒,blog,Java博客,程序员,个人博客,java開發,程序員,個人博客,Java">
    <meta name="description" content="大悲无泪，大悟无言，大笑无声。">
    <meta name="author" content="Resolmi">
    
    <title>
        
            NodeJS模仿Express封装路由 |
        
        Tadow
    </title>
    
<link rel="stylesheet" href="/css/style.css">

    <link rel="shortcut icon" href="https://static.imlgw.top/blog/20210731/BtJz541CcmJU.ico">
    <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/hexo-theme-keep@3.4.3/source/css/font-awesome.min.css">
    <script id="hexo-configurations">
    let KEEP = window.KEEP || {};
    KEEP.hexo_config = {"hostname":"imlgw.top","root":"/","language":"zh-CN","path":"search.json"};
    KEEP.theme_config = {"toc":{"enable":true,"number":true,"expand_all":true,"init_open":true},"style":{"primary_color":"#0066CC","avatar":"https://static.imlgw.top/blog/20210731/3C7hCSRR3lfq.png","favicon":"https://static.imlgw.top/blog/20210731/BtJz541CcmJU.ico","article_img_align":"left","left_side_width":"260px","content_max_width":"920px","hover":{"shadow":false,"scale":true},"first_screen":{"enable":true,"background_img":"/images/image.svg","description":"Keep It Simple & Stupid."},"scroll":{"progress_bar":{"enable":true},"percent":{"enable":true}}},"local_search":{"enable":true,"preload":false},"code_copy":{"enable":true,"style":"default"},"pjax":{"enable":true},"lazyload":{"enable":true},"version":"3.4.3"};
    KEEP.language_ago = {"second":"%s 秒前","minute":"%s 分钟前","hour":"%s 小时前","day":"%s 天前","week":"%s 周前","month":"%s 月前","year":"%s 年前"};
  </script>
<meta name="generator" content="Hexo 5.4.0"><link rel="stylesheet" href="/css/prism.css" type="text/css"></head>


<body>
<div class="progress-bar-container">
    
        <span class="scroll-progress-bar"></span>
    

    
        <span class="pjax-progress-bar"></span>
        <span class="pjax-progress-icon">
            <i class="fas fa-circle-notch fa-spin"></i>
        </span>
    
</div>


<main class="page-container">

    

    <div class="page-main-content">

        <div class="page-main-content-top">
            <header class="header-wrapper">

    <div class="header-content">
        <div class="left">
            
            <a class="logo-title" href="/">
                Tadow
            </a>
        </div>

        <div class="right">
            <div class="pc">
                <ul class="menu-list">
                    
                        <li class="menu-item">
                            <a class=""
                               href="/"
                            >
                                首页
                            </a>
                        </li>
                    
                        <li class="menu-item">
                            <a class=""
                               href="/archives"
                            >
                                归档
                            </a>
                        </li>
                    
                        <li class="menu-item">
                            <a class=""
                               href="/categories"
                            >
                                分类
                            </a>
                        </li>
                    
                        <li class="menu-item">
                            <a class=""
                               href="/sbe"
                            >
                                订阅
                            </a>
                        </li>
                    
                        <li class="menu-item">
                            <a class=""
                               href="/links"
                            >
                                友链
                            </a>
                        </li>
                    
                        <li class="menu-item">
                            <a class=""
                               href="/about"
                            >
                                关于
                            </a>
                        </li>
                    
                    
                        <li class="menu-item search search-popup-trigger">
                            <i class="fas fa-search"></i>
                        </li>
                    
                </ul>
            </div>
            <div class="mobile">
                
                    <div class="icon-item search search-popup-trigger"><i class="fas fa-search"></i></div>
                
                <div class="icon-item menu-bar">
                    <div class="menu-bar-middle"></div>
                </div>
            </div>
        </div>
    </div>

    <div class="header-drawer">
        <ul class="drawer-menu-list">
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/">首页</a>
                </li>
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/archives">归档</a>
                </li>
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/categories">分类</a>
                </li>
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/sbe">订阅</a>
                </li>
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/links">友链</a>
                </li>
            
                <li class="drawer-menu-item flex-center">
                    <a class=""
                       href="/about">关于</a>
                </li>
            
        </ul>
    </div>

    <div class="window-mask"></div>

</header>


        </div>

        <div class="page-main-content-middle">

            <div class="main-content">

                
                    <div class="fade-in-down-animation">
    <div class="article-content-container">

        <div class="article-title">
            <span class="title-hover-animation">NodeJS模仿Express封装路由</span>
        </div>

        
            <div class="article-header">
                <div class="avatar">
                    <img src="https://static.imlgw.top/blog/20210731/3C7hCSRR3lfq.png">
                </div>
                <div class="info">
                    <div class="author">
                        <span class="name">Resolmi</span>
                        
                            <span class="author-label">BOSS</span>
                        
                    </div>
                    <div class="meta-info">
                        <div class="article-meta-info">
    <span class="article-date article-meta-item">
        <i class="fas fa-edit"></i>&nbsp;2018-12-03 00:00:00
    </span>
    
        <span class="article-categories article-meta-item">
            <i class="fas fa-folder"></i>&nbsp;
            <ul>
                
                    <li>
                        <a href="/categories/Web/">Web</a>&nbsp;
                    </li>
                
            </ul>
        </span>
    
    
        <span class="article-tags article-meta-item">
            <i class="fas fa-tags"></i>&nbsp;
            <ul>
                
                    <li>
                        <a href="/tags/NodeJS/">NodeJS</a>&nbsp;
                    </li>
                
                    <li>
                        | <a href="/tags/ES6/">ES6</a>&nbsp;
                    </li>
                
                    <li>
                        | <a href="/tags/JavaScript/">JavaScript</a>&nbsp;
                    </li>
                
            </ul>
        </span>
    

    
    
        <span class="article-wordcount article-meta-item">
            <i class="fas fa-file-word"></i>&nbsp;<span>799 字</span>
        </span>
    
    
        <span class="article-min2read article-meta-item">
            <i class="fas fa-clock"></i>&nbsp;<span>4 分钟</span>
        </span>
    
    
        <span class="article-pv article-meta-item">
            <i class="fas fa-eye"></i>&nbsp;<span id="busuanzi_value_page_pv"></span>
        </span>
    
</div>

                    </div>
                </div>
            </div>
        

        <div class="article-content markdown-body">
            <h2 id="NodeJS模仿Express封装路由"><a href="#NodeJS模仿Express封装路由" class="headerlink" title="NodeJS模仿Express封装路由"></a>NodeJS模仿Express封装路由</h2><p><em>最近才开始学NodeJs也不知道为啥就突然对这个很感兴趣,(可能Java写烦了😄)，感觉用这个开发还是挺快的，而且性能也很好，借此也了解下函数式编程的特点和异步编程的思想。</em></p>
<ul>
<li><h3 id="没封装前"><a href="#没封装前" class="headerlink" title="没封装前"></a>没封装前</h3>原生的就差不多是这样的。</li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/* </span></span><br><span class="line"><span class="comment">    Node.js 未封装 1.0</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="keyword">const</span> http = require(<span class="string">&quot;http&quot;</span>);</span><br><span class="line"><span class="keyword">const</span> fs = require(<span class="string">&quot;fs&quot;</span>);</span><br><span class="line"><span class="keyword">const</span> path = require(<span class="string">&quot;path&quot;</span>);</span><br><span class="line"><span class="keyword">const</span> querystring = require(<span class="string">&quot;querystring&quot;</span>); <span class="comment">//json转换</span></span><br><span class="line"><span class="keyword">const</span> scores = require(<span class="string">&quot;./StudentScore.json&quot;</span>);</span><br><span class="line"><span class="keyword">const</span> template = require(<span class="string">&quot;art-template&quot;</span>);</span><br><span class="line">http.createServer((req, resp) =&gt; &#123;</span><br><span class="line">    <span class="keyword">if</span> (req.url.startsWith(<span class="string">&quot;/query&quot;</span>) &amp;&amp; req.method == <span class="string">&#x27;GET&#x27;</span>) &#123;</span><br><span class="line">        <span class="comment">//这里可以采用模板为了和下面的对比一下</span></span><br><span class="line">        fs.readFile(path.join(__dirname, <span class="string">&quot;querypage.html&quot;</span>), (err, content) =&gt; &#123;</span><br><span class="line">            <span class="keyword">if</span> (err) &#123;</span><br><span class="line">                resp.writeHead(<span class="number">500</span>, &#123;</span><br><span class="line">                    <span class="string">&#x27;Content-Type&#x27;</span>: <span class="string">&#x27;text/plain;charset=utf8&#x27;</span></span><br><span class="line">                &#125;);</span><br><span class="line">                resp.end(<span class="string">&#x27;服务器错误&#x27;</span>);</span><br><span class="line">            &#125;</span><br><span class="line">            resp.end(content);</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125; <span class="keyword">else</span></span><br><span class="line">    <span class="keyword">if</span> (req.url.startsWith(<span class="string">&quot;/scores&quot;</span>)) &#123;</span><br><span class="line">        let pdata = <span class="string">&#x27;&#x27;</span>;</span><br><span class="line">        <span class="comment">//事件绑定</span></span><br><span class="line">        <span class="comment">//获取数据（id）</span></span><br><span class="line">        req.on(<span class="string">&#x27;data&#x27;</span>, (ck) =&gt; &#123;</span><br><span class="line">            pdata += ck;</span><br><span class="line">        &#125;);</span><br><span class="line">        <span class="comment">//在这里返回</span></span><br><span class="line">        req.on(<span class="string">&#x27;end&#x27;</span>, () =&gt; &#123;</span><br><span class="line">            let obj = querystring.parse(pdata); <span class="comment">//将参数 的字符串转换成 对象</span></span><br><span class="line">            let result = scores[obj.stunum];</span><br><span class="line">            let content = template(path.join(__dirname, <span class="string">&quot;scores.art&quot;</span>), result);</span><br><span class="line">            resp.end(content);</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;).listen(<span class="number">9999</span>, () =&gt; &#123;</span><br><span class="line">    console.log(<span class="string">&#x27;Server is runing on 9999&#x27;</span>);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<ul>
<li>Express的方式<br>通过const app=express(); 获得一个app的对象后面就通过这个来操作<br><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="https://imlgwpicture.oss-cn-qingdao.aliyuncs.com/blogImage/D~KS%28D1%5B%5DUS5TBZPO7KTJ88.png"
                      alt="oss"
                ></li>
<li>手动封装</li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> url = require(<span class="string">&#x27;url&#x27;</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">//封装方法改变res  绑定res.send()</span></span><br><span class="line"><span class="function">function <span class="title">changeRes</span><span class="params">(res)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    res.send = function(data) &#123;</span><br><span class="line"></span><br><span class="line">        res.writeHead(<span class="number">200</span>, &#123;</span><br><span class="line">            <span class="string">&quot;Content-Type&quot;</span>: <span class="string">&quot;text/html;charset=utf-8&quot;</span></span><br><span class="line">        &#125;);</span><br><span class="line"></span><br><span class="line">        res.end(data);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//定义暴露的模块  return 里面定义的模块</span></span><br><span class="line"><span class="keyword">var</span> Server = function() &#123;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="keyword">var</span> G = <span class="keyword">this</span>; <span class="comment">/*全局变量*/</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">//处理get和post请求</span></span><br><span class="line">    <span class="keyword">this</span>._get = &#123;&#125;;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">this</span>._post = &#123;&#125;;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="keyword">var</span> app = function(req, res) &#123;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        changeRes(res);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//获取路由</span></span><br><span class="line">        <span class="keyword">var</span> pathname = url.parse(req.url).pathname;</span><br><span class="line">        <span class="keyword">if</span> (!pathname.endsWith(<span class="string">&#x27;/&#x27;</span>)) &#123;</span><br><span class="line">            pathname = pathname + <span class="string">&#x27;/&#x27;</span>;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//获取请求的方式 get  post</span></span><br><span class="line">        <span class="keyword">var</span> method = req.method.toLowerCase();</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (G[<span class="string">&#x27;_&#x27;</span> + method][pathname]) &#123;</span><br><span class="line"></span><br><span class="line">            <span class="keyword">if</span> (method == <span class="string">&#x27;post&#x27;</span>) &#123; <span class="comment">/*执行post请求*/</span></span><br><span class="line"></span><br><span class="line">                <span class="keyword">var</span> postStr = <span class="string">&#x27;&#x27;</span>;</span><br><span class="line">                req.on(<span class="string">&#x27;data&#x27;</span>, function(chunk) &#123;</span><br><span class="line"></span><br><span class="line">                    postStr += chunk;</span><br><span class="line">                &#125;)</span><br><span class="line">                req.on(<span class="string">&#x27;end&#x27;</span>, function(err, chunk) &#123;</span><br><span class="line">                    <span class="comment">//添加请求属性</span></span><br><span class="line">                    req.myBody = postStr; <span class="comment">/*表示拿到post的值*/</span></span><br><span class="line">                    <span class="comment">/*执行方法*/</span></span><br><span class="line">                    G[<span class="string">&#x27;_&#x27;</span> + method][pathname](req, res);</span><br><span class="line">                &#125;)</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123; <span class="comment">/*执行get请求*/</span></span><br><span class="line">                G[<span class="string">&#x27;_&#x27;</span> + method][pathname](req, res); <span class="comment">/*执行方法*/</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            res.end(<span class="string">&#x27;no router&#x27;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//下面的都是为了做注册的操作</span></span><br><span class="line">    app.get = function(string, callback) &#123;</span><br><span class="line">        <span class="keyword">if</span> (!string.endsWith(<span class="string">&#x27;/&#x27;</span>)) &#123;</span><br><span class="line">            string = string + <span class="string">&#x27;/&#x27;</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (!string.startsWith(<span class="string">&#x27;/&#x27;</span>)) &#123;</span><br><span class="line">            string = <span class="string">&#x27;/&#x27;</span> + string;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//    /login/</span></span><br><span class="line">        G._get[string] = callback;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    app.post = function(string, callback) &#123;</span><br><span class="line">        <span class="keyword">if</span> (!string.endsWith(<span class="string">&#x27;/&#x27;</span>)) &#123;</span><br><span class="line">            string = string + <span class="string">&#x27;/&#x27;</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (!string.startsWith(<span class="string">&#x27;/&#x27;</span>)) &#123;</span><br><span class="line">            string = <span class="string">&#x27;/&#x27;</span> + string;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//    /login/</span></span><br><span class="line">        G._post[string] = callback;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//G._post[&#x27;dologin&#x27;]=function(req,res)&#123;</span></span><br><span class="line">        <span class="comment">//</span></span><br><span class="line">        <span class="comment">//&#125;</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> app;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">module</span>.<span class="keyword">exports</span> = Server();</span><br></pre></td></tr></table></figure>

<ul>
<li>封装后<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> http = require(<span class="string">&quot;http&quot;</span>);</span><br><span class="line"><span class="keyword">const</span> url = require(<span class="string">&quot;url&quot;</span>);</span><br><span class="line"><span class="comment">//引入自定义的路由模块</span></span><br><span class="line"><span class="keyword">const</span> myApp = require(<span class="string">&quot;./model/express-route.js&quot;</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">//使用自定义的模块</span></span><br><span class="line">http.createServer(myApp).listen(<span class="number">9999</span>, () =&gt; &#123;</span><br><span class="line">    console.log(<span class="string">&#x27;Running 9999&#x27;</span>);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">myApp.get(<span class="string">&quot;/express&quot;</span>, (req, resp) =&gt; &#123;</span><br><span class="line">    resp.send(<span class="string">&quot;模仿Express封装路由&quot;</span>);</span><br><span class="line">    console.log(req);</span><br><span class="line">&#125;);</span><br><span class="line">myApp.post(<span class="string">&quot;/postExpress&quot;</span>, (req, resp) =&gt; &#123;</span><br><span class="line">    resp.send(<span class="string">&quot;模仿Express封装路由&quot;</span>);</span><br><span class="line">    console.log(req.myBody);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

</li>
</ul>
<hr>
<p>通过这个体会下Express的封装</p>

        </div>

        
            <div class="post-copyright-info">
                <div class="article-copyright-info-container">
    <ul>
        <li>本文标题：NodeJS模仿Express封装路由</li>
        <li>本文作者：Resolmi</li>
        <li>创建时间：2018-12-03 00:00:00</li>
        <li>
            本文链接：https://imlgw.top/2018/12/03/3b46123d/
        </li>
        <li>
            版权声明：本博客所有文章除特别声明外，均采用 <a class="license" target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">BY-NC-SA</a> 许可协议。转载请注明出处！
        </li>
    </ul>
</div>

            </div>
        

        
            <div class="article-nav">
                
                    <div class="article-prev">
                        <a class="prev"
                           rel="prev"
                           href="/2018/12/11/83535e94/"
                        >
                            <span class="left arrow-icon flex-center">
                              <i class="fas fa-chevron-left"></i>
                            </span>
                            <span class="title flex-center">
                                <span class="post-nav-title-item">常见的排序算法总结</span>
                                <span class="post-nav-item">上一篇</span>
                            </span>
                        </a>
                    </div>
                
                
                    <div class="article-next">
                        <a class="next"
                           rel="next"
                           href="/2018/11/30/ada76fed/"
                        >
                            <span class="title flex-center">
                                <span class="post-nav-title-item">Java爬虫实战(一) ：爬取斗图社所有gif</span>
                                <span class="post-nav-item">下一篇</span>
                            </span>
                            <span class="right arrow-icon flex-center">
                              <i class="fas fa-chevron-right"></i>
                            </span>
                        </a>
                    </div>
                
            </div>
        

        
            <div class="comment-container">
                <div class="comments-container">
    <div id="comment-anchor"></div>
    <div class="comment-area-title">
        <i class="fas fa-comments">&nbsp;评论</i>
    </div>
    

        
            <section class="disqus-comments">
<div id="disqus_thread">
  <noscript>Please enable JavaScript to view the <a target="_blank" rel="noopener" href="//disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>
</section>

<script>
var disqus_shortname = 'imlgw';

var disqus_url = 'https://imlgw.top/2018/12/03/3b46123d/';

(function(){
  var dsq = document.createElement('script');
  dsq.type = 'text/javascript';
  dsq.async = true;
  dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
  (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>

<script id="dsq-count-scr" src="//imlgw.disqus.com/count.js" async></script>
        
    
</div>

            </div>
        
    </div>
</div>


                
            </div>

        </div>

        <div class="page-main-content-bottom">
            <footer class="footer">
    <div class="info-container">
        <div class="copyright-info info-item">
            &copy;
            
              <span>2018</span>&nbsp;-&nbsp;
            
            2021&nbsp;<i class="fas fa-heart icon-animate"></i>&nbsp;<a href="/">Resolmi</a>
        </div>
        
            <script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
            <div class="website-count info-item">
                
                    <span id="busuanzi_container_site_uv">
                        访问人数&nbsp;<span id="busuanzi_value_site_uv"></span>&ensp;
                    </span>
                
                
                    <span id="busuanzi_container_site_pv">
                        总访问量&nbsp;<span id="busuanzi_value_site_pv"></span>
                    </span>
                
            </div>
        
        
            <div class="icp-info info-item"><a target="_blank" rel="nofollow" href="https://beian.miit.gov.cn">鄂ICP备18011208号</a></div>
        
    </div>
</footer>

        </div>
    </div>

    
        <div class="post-tools">
            <div class="post-tools-container">
    <ul class="tools-list">
        <!-- TOC aside toggle -->
        
            <li class="tools-item page-aside-toggle">
                <i class="fas fa-outdent"></i>
            </li>
        

        <!-- go comment -->
        
            <li class="go-comment">
                <i class="fas fa-comment"></i>
            </li>
        
    </ul>
</div>

        </div>
    

    <div class="right-bottom-side-tools">
        <div class="side-tools-container">
    <ul class="side-tools-list">
        <li class="tools-item tool-font-adjust-plus flex-center">
            <i class="fas fa-search-plus"></i>
        </li>

        <li class="tools-item tool-font-adjust-minus flex-center">
            <i class="fas fa-search-minus"></i>
        </li>

        <li class="tools-item tool-expand-width flex-center">
            <i class="fas fa-arrows-alt-h"></i>
        </li>

        <li class="tools-item tool-dark-light-toggle flex-center">
            <i class="fas fa-moon"></i>
        </li>

        <!-- rss -->
        

        

        <li class="tools-item tool-scroll-to-bottom flex-center">
            <i class="fas fa-arrow-down"></i>
        </li>
    </ul>

    <ul class="exposed-tools-list">
        <li class="tools-item tool-toggle-show flex-center">
            <i class="fas fa-cog fa-spin"></i>
        </li>
        
            <li class="tools-item tool-scroll-to-top flex-center">
                <i class="arrow-up fas fa-arrow-up"></i>
                <span class="percent"></span>
            </li>
        
    </ul>
</div>

    </div>

    
        <aside class="page-aside">
            <div class="post-toc-wrap">
    <div class="post-toc">
        <ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#NodeJS%E6%A8%A1%E4%BB%BFExpress%E5%B0%81%E8%A3%85%E8%B7%AF%E7%94%B1"><span class="nav-number">1.</span> <span class="nav-text">NodeJS模仿Express封装路由</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%B2%A1%E5%B0%81%E8%A3%85%E5%89%8D"><span class="nav-number">1.1.</span> <span class="nav-text">没封装前</span></a></li></ol></li></ol>
    </div>
</div>
        </aside>
    

    <div class="image-viewer-container">
    <img src="">
</div>


    
        <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
          <span class="search-input-field-pre">
            <i class="fas fa-keyboard"></i>
          </span>
            <div class="search-input-container">
                <input autocomplete="off"
                       autocorrect="off"
                       autocapitalize="off"
                       placeholder="搜索..."
                       spellcheck="false"
                       type="search"
                       class="search-input"
                >
            </div>
            <span class="popup-btn-close">
                <i class="fas fa-times"></i>
            </span>
        </div>
        <div id="search-result">
            <div id="no-result">
                <i class="fas fa-spinner fa-pulse fa-5x fa-fw"></i>
            </div>
        </div>
    </div>
</div>

    

</main>



<script src="//cdn.jsdelivr.net/npm/hexo-theme-keep@3.4.3/source/js/utils.js"></script><script src="//cdn.jsdelivr.net/npm/hexo-theme-keep@3.4.3/source/js/main.js"></script><script src="//cdn.jsdelivr.net/npm/hexo-theme-keep@3.4.3/source/js/header-shrink.js"></script><script src="//cdn.jsdelivr.net/npm/hexo-theme-keep@3.4.3/source/js/back2top.js"></script><script src="//cdn.jsdelivr.net/npm/hexo-theme-keep@3.4.3/source/js/dark-light-toggle.js"></script>


    <script src="//cdn.jsdelivr.net/npm/hexo-theme-keep@3.4.3/source/js/local-search.js"></script>



    <script src="//cdn.jsdelivr.net/npm/hexo-theme-keep@3.4.3/source/js/code-copy.js"></script>



    <script src="//cdn.jsdelivr.net/npm/hexo-theme-keep@3.4.3/source/js/lazyload.js"></script>


<div class="post-scripts pjax">
    
        <script src="//cdn.jsdelivr.net/npm/hexo-theme-keep@3.4.3/source/js/left-side-toggle.js"></script><script src="//cdn.jsdelivr.net/npm/hexo-theme-keep@3.4.3/source/js/libs/anime.min.js"></script><script src="//cdn.jsdelivr.net/npm/hexo-theme-keep@3.4.3/source/js/toc.js"></script>
    
</div>


    <script src="//cdn.jsdelivr.net/npm/hexo-theme-keep@3.4.3/source/js/libs/pjax.min.js"></script>
<script>
    window.addEventListener('DOMContentLoaded', () => {
        window.pjax = new Pjax({
            selectors: [
                'head title',
                '.page-container',
                '.pjax'
            ],
            history: true,
            debug: false,
            cacheBust: false,
            timeout: 0,
            analytics: false,
            currentUrlFullReload: false,
            scrollRestoration: false,
            // scrollTo: true,
        });

        document.addEventListener('pjax:send', () => {
            KEEP.utils.pjaxProgressBarStart();
        });

        document.addEventListener('pjax:complete', () => {
            KEEP.utils.pjaxProgressBarEnd();
            window.pjax.executeScripts(document.querySelectorAll('script[data-pjax], .pjax script'));
            KEEP.refresh();
        });
    });
</script>



<script src="https://cdn.jsdelivr.net/npm/live2d-widget@3.x/lib/L2Dwidget.min.js"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"https://cdn.jsdelivr.net/npm/live2d-widget-model-hijiki@1.0.5/assets/hijiki.model.json"},"display":{"superSample":2,"width":160,"height":320,"position":"right","hOffset":0,"vOffset":-70},"mobile":{"show":false,"scale":0.2},"log":false});</script></body>
</html>
